﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MagicEffectBehavior : IAnimationInit {
    private IEffect magic;
    private Transform mSpawnPos;
    private Transform mtagert;//生成目标位置
    public Vector3 offset = Vector3.zero;
    public override void OnStart(AnimationBehaviorInit anb)
    {
        //Debug.Log(Facade.Instance == null);
        //Debug.Log(Facade.Instance.effects == null);
        mtagert = anb.transform;
        GameObject go = Facade.Instance.Effects.Initiate(0, mtagert.position + offset);
        go.SetActive(false);
        mSpawnPos = go.transform;
        magic = go.GetComponent<IEffect>();
       
       // Debug.Log(magic == null);
    }
    public override void OnStateEnter(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex)
    {
        // Debug.Log("state enter"+(magic==null));
        Updata();
        magic.Enable();
    }


    public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        magic.Disable();
        //Debug.Log("state exit");
    }

    public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        Updata();
    }
    private void Updata()
    {
        mSpawnPos.position = mtagert.position + offset;
    }
}
